﻿using System;
using System.Collections.Generic;

using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

public partial class Web_Editstock : System.Web.UI.Page
{
    string order;
    string proname;
    decimal qty;
    protected void Page_Load(object sender, EventArgs e)
    {
        Session["current"] = "Edit Purchase Order";//current page
        if (Session["user"] != null)//check user
        {
            string user = Session["user"].ToString();
            if (user == "viewer")
            {
                Response.Redirect("index.aspx");
            }

        }
        else
        {
            Response.Redirect("index.aspx");
        }
    }
    protected void ASPxGridView2_RowUpdating(object sender, DevExpress.Web.Data.ASPxDataUpdatingEventArgs e)
    {
        //Bestlife.ERP.Entities.E_PurchaseOrder order = new Bestlife.ERP.Entities.E_PurchaseOrder();
        //order.Approval = Convert.ToString(e.NewValues[""]);
        //order.Contrat = Convert.ToString(e.NewValues[""]);
        //order.Description = Convert.ToString(e.NewValues[""]);
        //order.Due = Convert.ToDateTime(e.NewValues[""]);
        //order.Issu = Convert.ToDateTime(e.NewValues[""]);
        //order.Or_ID1 = Convert.ToString(e.NewValues[""]);
        //order.Proname = Convert.ToString(e.NewValues[""]);
        //order.Qty = Convert.ToDecimal(e.NewValues[""]);
        //order.Supplier = Convert.ToString(e.NewValues[""]);
        //order.Total = Convert.ToDecimal(e.NewValues[""]);
        //order.Unitvalue = Convert.ToDecimal(e.NewValues[""]);

        //Bestlife.ERP.BusinessRules.

    }
    protected void ASPxButton1_Click(object sender, EventArgs e)
    {
        List<Bestlife.ERP.Entities.E_GRN> listgrn = new List<Bestlife.ERP.Entities.E_GRN>();
        Bestlife.ERP.Entities.E_GRN grn = new Bestlife.ERP.Entities.E_GRN();
        int i = ASPxGridView2.VisibleRowCount;

        List<Object> itemid1 = ASPxGridView2.GetSelectedFieldValues("Pro_Name");
        List<Object> itemid = ASPxGridView2.GetSelectedFieldValues("Or_ID");
        List<Object> itemid2 = ASPxGridView2.GetSelectedFieldValues("qty");
        int j = itemid.Count;
        string user = Session["username"].ToString();
        if (DropDownList2.SelectedValue != "")
        {
            if (DropDownList2.SelectedValue == "YES")
            {

                if (itemid.Count == 0 || itemid1.Count == 0 || itemid2.Count == 0)
                {
                    ASPxLabel4.Visible = true;
                    ASPxLabel4.Text = "Please select order items ";
                }
                else
                {
                    foreach (object selectitemid in itemid)
                    {
                        order = selectitemid.ToString();
                    }

                    foreach (object selectitemid1 in itemid1)
                    {
                        proname = selectitemid1.ToString();
                    }
                    foreach (object selectitemid2 in itemid2)
                    {
                        qty = decimal.Parse(selectitemid2.ToString());
                    }

                    string approval = DropDownList2.SelectedValue;
                    Boolean result = Bestlife.ERP.BusinessRules.B_PurchaseOrder.approval(listgrn, approval, user, itemid.Count);
                    if (result)
                    {
                        ASPxLabel5.Visible = true;
                        ASPxLabel5.Text = "Order Approved Successfully";
                    }
                    if (i == j)
                    {
                        string approve = "YES";

                        Bestlife.ERP.BusinessRules.B_PurchaseOrder.allapprove(listgrn, user, approve, itemid.Count);
                    }
                }
            }
        }
    }
}